#[cfg(test)]
mod redis {
    use std::time::Duration;

    use redis::Commands;

    fn redis() {
        // The URL format is redis://[<username>][:<password>@]<hostname>[:port][/<db>]
        // redis+unix:///<path>[?db=<db>[&pass=<password>][&user=<username>]]
        // For compatibility with some other redis libraries, the “unix” scheme is also supported:
        // unix:///<path>[?db=<db>][&pass=<password>][&user=<username>]]
        let client = redis::Client::open("redis://:admin@192.168.8.20:6379/0").unwrap();
        client
            .get_connection_with_timeout(Duration::new(2, 0))
            .unwrap();
        let mut connection = client.get_connection().unwrap();
        let _: () = connection.set("test", "test_data").unwrap();
        let rv: String = connection.get("test").unwrap();
        println!("{}", rv)
    }

    #[test]
    fn char() {
        redis()
    }
}

#[cfg(test)]
mod mongo {
    use mongodb::{Client, options::ClientOptions};

    const URI: &str = "mongodb://root:root@192.168.8.20:27017";

    async fn mongo() {
        let mut client_options = ClientOptions::parse(URI).await.unwrap();
        client_options.app_name = Some("My App".to_string());
        let client = Client::with_options(client_options).unwrap();
        for db_name in client.list_database_names(None, None).await.unwrap() {
            println!("{:?}", db_name);
        }
        println!("{:?}", "-------------------");
    }

    async fn database() {
        // Get a handle to a database.
        let mut client_options = ClientOptions::parse(URI).await.unwrap();
        client_options.app_name = Some("My App".to_string());
        let client = Client::with_options(client_options).unwrap();
        let db = client.database("1Panel");
        for collection_name in db.list_collection_names(None).await.unwrap() {
            println!("{}", collection_name);
        }
    }

    #[tokio::test]
    async fn char() {
        mongo().await;
        database().await
    }
}
